<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新增兼任登记人员')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>工号：</p>
                            <input type="text" name="badge"/>
                        </li>
                        <li>
                            <p>姓名：</p>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>

<script th:inline="javascript">
    var prefix = ctx + 'changeManage/EmpConcurrentlyManage';
    $(function () {
        queryData();
    })

    function queryData() {
        var columns = [];
        var checkbox = {checkbox: true};
        var badge = {field: 'badge', title: '工号'};
        var name = {field: 'name', title: '姓名'};
        var eName = {field: 'eName', title: '英文名'};
        var compName = {field: 'compName', title: '公司名称'};
        var depName = {field: 'depName', title: '部门名称'};
        var jobName = {field: 'jobName', title: '工作岗位'};
        var empStatusName = {field: 'empStatusName', title: '员工状态'};
        var jobStatusName = {field: 'jobStatusName', title: '在岗状态'};
        var ReportToName = {field: 'ReportToName', title: '行政上级'};
        var WfReportToName = {field: 'WfReportToName', title: '职能上级'};
        var empTypeName = {field: 'empTypeName', title: '员工类型'};
        var empGradeName = {field: 'empGradeName', title: '员工级别'};
        var WorkCity = {field: 'WorkCity', title: '工作城市'};

        columns.push(checkbox, badge, name, eName, compName, depName, jobName, empStatusName, jobStatusName);
        columns.push(ReportToName, WfReportToName, empTypeName, empGradeName, WorkCity);

        var options = {
            uniqueId: "id",
            url: prefix + '/addRegister',
            modalName: "添加员工",
            height: $(window).height() - 110,
            columns: columns
        };
        $.table.init(options);
    }

    function add() {
        var allEid = "";
        var allName = "";
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length == 0) {
            $.modal.alertWarning("请选择一条职员");
            return;
        }
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allEid += row[i].eid;
                allName += row[i].name;
            } else {
                allEid += row[i].eid + ",";
                allName += row[i].name + ",";
            }
        }

        $.ajax({
            async: false,
            url: prefix + "/addProcedure",
            data: {
                "allEid": allEid,
                "allName": allName,
                "procedure": "eSP_PartOrgAddEmp",
                "type": "1"
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                //todo 这里需要判断data返回值
                if (data.code == 0) {
                    // $.modal.alertWarning("添加成功！");
                    // $.operate.successCallback(data);
                    $.modal.close();
                    parent.$.modal.msgSuccess(data.message);
                    parent.$.table.refresh();
                } else if (data.code == 500) {
                    $.modal.alertWarning("服务繁忙");
                } else {
                    $.modal.alertWarning(data.message);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function submitHandler() {
        add();
    }

</script>
</body>
</html>